<script src="<{$js_dir}>jquery.ui.widget.js"></script>
<script src="<{$js_dir}>jquery.fileupload.js"></script>
<div class="uploader_box">
	<div class="">
		<input type="hidden" name="attids" value="<{$attids}>" id="aid" />
		<span class="btn btn-success fileinput-button input-sm">
			<i class="glyphicon glyphicon-plus"></i>
			<span>上传图片</span>
			<input  class="" id="fileupload" type="file"  data-url="<{:U('Component/Attachment/upload')}>" [type] />
			<!-- <input id="fileupload" type="file" name="files[]" data-url="./php/index.php" multiple> -->
		</span>
		<span class="showatt">
			<php>
				if($attids){
					$attArr = explode(',', $attids);
					$img = '';
					foreach($attArr as $v){
					
						$str = '<img src="%s" />';
						$link = U('Component/Attachment/read',array('id'=>$v));
						$str = sprintf($str,$link);
						$img .= $str;
					}
					echo $img;
				}
			</php>
		</span>
	</div>
	
</div>
<script type="text/javascript">
	$(function () {
	var aid = $('#aid') .val();
	    $('#fileupload').fileupload({
	        dataType: 'json',
	        done: function (e, data) {
	        	if(data.result.errcode == 0)
	        	{
	        		if($('#fileupload').attr('multiple')){

	        			$('.showatt').append('<img src="'+data.result.result.att_url+'"/>');
	        			if(aid !=='' ){
	        				aid = aid+','+data.result.result.aid;
		        		}else{
		        			aid = data.result.result.aid;
		        		}
	        		}else{
	        			$('.showatt').html('<img src="'+data.result.result.att_url+'"/>');
	        			aid = data.result.result.aid;
	        		}

	        		$('#aid') .val(aid);
	        	}else{
	        		$('#messagebox').message(data.result.errmsg);
	        	}
	        }
	    });
	});
</script>
